#!/bin/sh

pwd=$(dirname ${PWD})

THRIFT_VER=0.12.0
THRIFT_IMG=thrift:${THRIFT_VER}
THRIFT="docker run --rm -u $(id -u) -v ${pwd}:/data ${THRIFT_IMG} thrift"

args=$(echo $@ | sed "s|${pwd}|/data|g")

echo Running Docker-based Thrift in pwd=${pwd}
echo 'Remapped arguments:' $@
echo '                to:' $args

set -x
set -e

${THRIFT} $args

# docker command runs as root, but we need normal permissions
if test ! -r ${pwd}/jaeger-thrift/src/main/gen-java; then
  sudo chmod -R 0777 ${pwd}/jaeger-thrift/src/main/gen-java
fi
